package com.chen.winnerframework.util;

import cn.hutool.core.collection.CollUtil;
import com.chen.winnerframework.constants.CommonConstants;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;
import java.util.regex.Pattern;

/**
 * redis 工具类
 *
 * @author chengy
 * @date 2022/11/29
 */
public class RedisUtil {

    /**
     * 清除菜单缓存
     */
    public static void clearMenuCache(RedisTemplate<String, Object> redisTemplate) {
        String key = Pattern.matches("\\*$", CommonConstants.MENU_KEY) ?
                CommonConstants.MENU_KEY : CommonConstants.MENU_KEY + "*";
        Set<String> keys = redisTemplate.keys(key);
        if (CollUtil.isNotEmpty(keys)) {
            redisTemplate.delete(keys);
        }
    }

}
